package com.bjsxt.details.service.impl;

import com.bjsxt.details.dao.ItemDetailDao;
import com.bjsxt.details.service.DetailsService;
import com.bjsxt.livegoods.pojo.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName : DetailsServiceImpl
 * @Description :
 * @Author : ZWZ
 * @Date: 2021/8/26 9:40
 */
@Service
public class DetailsServiceImpl implements DetailsService {

    @Autowired
    private ItemDetailDao itemDetailDao;
    @Value("${livegoods.banner.nginx.prefix}")
    private String nginxPrefix;

    @Cacheable(cacheNames = "com:livegoods:details", key = "'getDetails('+#id+')'")
    @Override
    public Item getDetails(String id) {
        Item item = itemDetailDao.findItemById(id);
        if (Objects.isNull(item)) {
            return null;
        }
        List<String> newImgList = new ArrayList<>();
        for (String img : item.getImgs()) {
            newImgList.add(nginxPrefix + img);
        }
        item.setImgs(newImgList);
        return item;
    }

}

